package cn.libinal.scloud.base.common.jackson;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.springframework.boot.jackson.JsonComponent;

import java.io.IOException;
import java.text.DecimalFormat;

/**
 * @author libinal
 */
@JsonComponent
public class CustomSerialize {
    public static class CustomDoubleSerialize extends JsonSerializer<Double> {
        private DecimalFormat df = new DecimalFormat("###,###,###.00");

        @Override
        public void serialize(Double value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
            if (value != null) {
                jsonGenerator.writeString(df.format(value));
            }
        }
    }
}
